package com.cefa.edu.dao;


import com.cefa.edu.model.Graduation;
import com.cefa.edu.model.ScoreInfo;
import com.cefa.edu.model.Score;
import com.cefa.edu.pojo.SignatureRecord;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import javax.websocket.server.PathParam;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface ScoreMapper {
    @Select("select user_id,level_id,course_id,student_name,education_stage_name,grade_name,course_name, examination_time,recording_person,recording_time,fraction, manager_check_status,instructor_check_status,guardian_check_status,guardian_check_sign_data,instructor_check_sign_data,manager_check_sign_data from cefa_edu_score where id=#{scoreId}")
    @Results(id="scoreMap1", value = {
            @Result(property = "id",column = "id"),
            @Result(property = "courseId",column = "course_id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "levelId",column = "level_id"),
            @Result(property = "studentName",column = "student_name"),
            @Result(property = "eduStageId",column = "education_stage_id"),
            @Result(property = "eduStageName",column = "education_stage_name"),
            @Result(property = "gradeName",column = "grade_name"),
            @Result(property = "className",column = "class_name"),
            @Result(property = "courseName",column = "course_name"),
            @Result(property = "recordingName",column = "recording_name"),
            @Result(property = "examinationTime",column = "examination_time"),
            @Result(property = "recordingPerson",column = "recording_person"),
            @Result(property = "recordingTime",column = "recording_time"),
            @Result(property = "fraction",column = "fraction"),
            @Result(property = "managerCheckStatus",column = "manager_check_status"),
            @Result(property = "managerCheckName",column = "manager_check_name"),
            @Result(property = "instructorCheckStatus",column = "instructor_check_status"),
            @Result(property = "instructorCheckName",column = "instructor_check_name"),
            @Result(property = "guardianCheckStatus",column = "guardian_check_status"),
            @Result(property = "guardianCheckName",column = "guardian_check_name"),
            @Result(property = "roleType",column = "role_type"),
            @Result(property = "chainStatus",column = "chain_status"),
            @Result(property = "guardianCheckSignData",column = "guardian_check_sign_data"),
            @Result(property = "instructorCheckSignData",column = "instructor_check_sign_data"),
            @Result(property = "managerCheckSignData",column = "manager_check_sign_data")


    })
    com.cefa.edu.pojo.Score getScoreById(@Param("scoreId") Integer scoreId);
    /**
     * 按照时间（升序）、分数排序（降序）
     * 根据学段id、学生id 获取学生分数数据
     */
    @Select({"select s.* from cefa_edu_score s where s.user_id=#{userId} and s.education_stage_id=#{eduStageId} order by s.examination_time asc,s.fraction desc"})
    @Results(id="scoreMap", value = {
            @Result(property = "id",column = "id"),
            @Result(property = "courseId",column = "course_id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "levelId",column = "level_id"),
            @Result(property = "studentName",column = "student_name"),
            @Result(property = "eduStageId",column = "education_stage_id"),
            @Result(property = "eduStageName",column = "education_stage_name"),
            @Result(property = "gradeName",column = "grade_name"),
            @Result(property = "className",column = "class_name"),
            @Result(property = "courseName",column = "course_name"),
            @Result(property = "recordingName",column = "recording_name"),
            @Result(property = "examinationTime",column = "examination_time"),
            @Result(property = "recordingPerson",column = "recording_person"),
            @Result(property = "recordingTime",column = "recording_time"),
            @Result(property = "fraction",column = "fraction"),
            @Result(property = "managerCheckStatus",column = "manager_check_status"),
            @Result(property = "managerCheckName",column = "manager_check_name"),
            @Result(property = "instructorCheckStatus",column = "instructor_check_status"),
            @Result(property = "instructorCheckName",column = "instructor_check_name"),
            @Result(property = "guardianCheckStatus",column = "guardian_check_status"),
            @Result(property = "guardianCheckName",column = "guardian_check_name"),
            @Result(property = "roleType",column = "role_type"),
            @Result(property = "chainStatus",column = "chain_status")


    })
    List<HashMap<String,Object>> getScoresByUserIdAndEduStageId(@Param("userId") Integer userId, @Param("eduStageId")Integer eduStageId);


    /**
     * @aa 根据学生id 获取学生成绩数据
     *  按照时间（升序）、分数排序（降序）
     * 根据学段id、学生id 获取学生分数数据
     */
    @Select({"SELECT s.* FROM cefa_edu_score s WHERE s.user_id = #{userId} and s.chain_status=3 order by s.examination_time desc"})
    @ResultMap(value = "scoreMap")
    List<HashMap<String,Object>> getScoresByUserId(Integer userId);


    @Select("select * from cefa_edu_score where user_id=#{user_id}")
    List<Score> findByUserId(@Param("user_id") Integer user_id);

    @Insert("insert into \n" +
            "cefa_edu_score (course_id,user_id,level_id,student_name,education_stage_name,grade_name,\n" +
            "class_name,course_name,recording_name,examination_time,recording_time,recording_person,fraction)\n" +
            "VALUES(#{course_id},#{user_id},#{level_id},#{student_name},#{education_stage_name},#{grade_name},#{class_name},#{course_name}," +
            "#{recording_name},#{examination_time},#{recording_time},#{recording_person},#{fraction})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void saveStudentScore(Score score);


    /**
     * 为管理者角色时，根据权限查询学生成绩信息（分页后期+）
     * @param ids
     * @return
     */
    @Select("select id, student_name,grade_name,class_name,recording_name,fraction,recording_time from cefa_edu_score where education_stage_id=#{ids} and chain_status=#{chainStatus}")
    List<ScoreInfo> studentChainData(@Param("ids") String ids,@Param("chainStatus") Integer chainStatus);
    @Select({"<script>",
            "SELECT * FROM cefa_edu_score",
            "WHERE",
            "<when test='status==1&amp;&amp;state==1'>",
            " (education_stage_id  in(#{gids})  or  grade_id in (${pids}) <when test='levelId!=null'> or level_id in (${levelId})</when> <when test='courseIds!=null'> or course_id in (${courseIds})</when>) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==1&amp;&amp;state==0'>",
            " (education_stage_id  in(#{gids})  or  grade_id in (${pids})) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==2&amp;&amp;state==1'>",
            " (grade_id in (${pids}) <when test='levelId!=null'> or level_id in (${levelId})</when> <when test='courseIds!=null'> or course_id in (${courseIds})</when>) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==2&amp;&amp;state==0'>",
            " grade_id in (${pids}) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==3&amp;&amp;state==1'>",
            " (education_stage_id  in(#{gids}) <when test='levelId!=null'> or level_id in (${levelId})</when> <when test='courseIds!=null'> or course_id in (${courseIds})</when>) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==3&amp;&amp;state==0'>",
            " education_stage_id  in(#{gids}) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==4&amp;&amp;state==1 &amp;&amp;levelCount>0'>",
            " (level_id in (${levelId}) <when test='courseIds!=null'> or course_id in (${courseIds})</when>) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==4&amp;&amp;state==1 &amp;&amp;levelCount==0'>",
            "  course_id in (${courseIds}) and chain_status=#{chainStatus}",
            "</when>",
            "</script>"})
    List<ScoreInfo> getScoreByids(@Param("status") Integer status, @Param("state") Integer state,@Param("levelId") String levelId,@Param("courseIds") String courseIds, @Param("pids") String pids, @Param("gids") String gids, @Param("chainStatus") Integer chainStatus,@Param("levelCount") Integer levelCount);

    /**
     * 根据用户（老师）id查询学生成绩信息
     * @param userId
     * @return
     */
    @Select("select c.id, c.student_name,c.grade_name,c.class_name,c.recording_name,c.fraction,c.recording_time from cefa_edu_score c left join cefa_edu_user_education_level ul on c.level_id=ul.level_id where ul.user_id=#{userId} and c.chain_status=#{chainStatus}")
    List<ScoreInfo> getScoreInfoByUserId(@Param("userId") Integer userId,@Param("chainStatus") Integer chainStatus);

    /**
     * 根据用户（学生）id查询学生成绩信息
     * @param userId
     * @return
     */
    @Select("select id, student_name,grade_name,class_name,recording_name,fraction,recording_time from cefa_edu_score where user_id=#{userId} and chain_status=#{chainStatus} ")
    List<ScoreInfo> getScoreInfoByUserId2(@Param("user_id") Integer userId,@Param("chainStatus") Integer chainStatus);

    @Select({"<script>",
            "SELECT * FROM cefa_edu_score",
            "WHERE",
            "<when test='levelCount>0'>",
            " (level_id in (${levelIds}) <when test='courseIds!=null'> or course_id in (${courseIds})</when>) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='levelCount==0'>",
            " course_id in (${courseIds}) and chain_status=#{chainStatus}",
            "</when>",
            "</script>"})
    List<ScoreInfo> getScoreByids2(@Param("levelIds") String levelIds,@Param("courseIds") String courseIds,@Param("chainStatus") Integer chainStatus,@Param("levelCount") Integer levelCount);





    //-----------------------------------------------------------------------------------------------------------------------------------------------------





    /**
     * 根据教育阶段的id和上链状态
     * @param phaseIds
     * @param chainStatus
     * @return
     */
    //@Select({"select id, student_name,grade_name,class_name,recording_name,fraction,recording_time from cefa_edu_score where education_stage_id in (#{phaseIds}) and chain_status=#{chainStatus} "})
    @Select({"<script>",
            "SELECT *,1 as role_type FROM cefa_edu_score",
            "WHERE education_stage_id in (${phaseIds}) and chain_status=#{chainStatus}",
            "<when test='type==1'>",
            " and manager_check_status=0",
            "</when>",
            " order by id",
            "<when test='pageNo!=null'>",
            " LIMIT #{pageNo}, #{pageCount}",
            "</when>",
            "</script>"})
    @ResultMap(value = "scoreMap1")
    List<com.cefa.edu.pojo.Score> getScoreByPhaseIds(@Param("phaseIds") String phaseIds,@Param("chainStatus") Integer chainStatus,@Param("pageNo") Integer pageNo,@Param("pageCount") Integer pageCount,@Param("type") Integer type);

    /**
     * 数量
     * @param phaseIds
     * @param chainStatus
     * @param type
     * @return
     */
    @Select({"<script>",
            "SELECT count(1) FROM cefa_edu_score",
            "WHERE education_stage_id in (${phaseIds}) and chain_status=#{chainStatus}",
            "<when test='type==1'>",
            " and manager_check_status=0",
            "</when>",
            "</script>"})
    int getScoreByPhaseIdsCount(@Param("phaseIds") String phaseIds,@Param("chainStatus") Integer chainStatus,@Param("type") Integer type);

    /**
     * 根据上链状态和用户id查询学生成绩信息
     * @param userId
     * @param chainStatus
     * @return
     */
    //@Select("select id, course_id,user_id,level_id,student_name,education_stage_name,manager_check_status,instructor_check_status,guardian_check_status,chain_status,grade_name,class_name,course_name,recording_name,examination_time,recording_person,recording_time,fraction,manager_check_name,instructor_check_name,guardian_check_name from cefa_edu_score where user_id=#{userId} and chain_status=#{chainStatus} ")
    @Select({"<script>",
            "SELECT *,6 as role_type FROM cefa_edu_score",
            "WHERE  user_id=#{userId} and chain_status=#{chainStatus} <when test='type==1'> and guardian_check_status=0</when> ",
            " ORDER BY id",
            "<when test='pageNo!=null'>",
            " LIMIT #{pageNo}, #{pageCount}",
            "</when>",
            "</script>"})
    @ResultMap(value = "scoreMap1")
    List<com.cefa.edu.pojo.Score> getScoreByUserId(@Param("userId") Integer userId,@Param("chainStatus") Integer chainStatus,@Param("pageNo") Integer pageNo,@Param("pageCount") Integer pageCount,@Param("type") Integer type);
    @Select({"<script>",
            "SELECT count(1) FROM cefa_edu_score",
            "WHERE  user_id=#{userId} and chain_status=#{chainStatus} <when test='type==1'> and guardian_check_status=0</when> ",
            "</script>"})
    int getScoreByUserIdCount(@Param("userId") Integer userId,@Param("chainStatus") Integer chainStatus,@Param("type") Integer type);

    /**
     * 查询管理者的学生的状态成绩(一级、二级)
     * add by chaijian 2018-09-06
     * @return
     */
    @Select({"<script>",
            "SELECT *,2 as role_type FROM cefa_edu_score",
            "WHERE",
            "<when test='roleType==2'>",
            " education_stage_id  in(${phaseIdsForRoleType2}) and chain_status=#{chainStatus} <when test='type==1'> and manager_check_status=0</when>",
            "</when>",
            "<when test='roleType==3'>",
            " education_stage_id in(${phaseIdsForRoleType3}) and  grade_id in (${gradeIdsForRoleType3})  and chain_status=#{chainStatus} <when test='type==1'> and manager_check_status=0</when> ",
            "</when>",
            "<when test='roleType==4'>",
            "level_id in (${classIdsForRoleType4}) and chain_status=#{chainStatus} <when test='type==1'> and instructor_check_status=0</when>",
            "</when>",
            "<when test='roleType==5'>",
            "level_id in (${classIdsForRoleType5}) and course_id in(${courseIdsForRoleType5}) and chain_status=#{chainStatus} <when test='type==1'> and instructor_check_status=0</when>",
            "</when>",
            "<when test='roleType==6'>",
            "user_id=#{studentId} and chain_status=#{chainStatus} <when test='type==1'> and guardian_check_status=0</when>",
            "</when>",
            "<when test='roleType==7'>",
            "user_id=#{studentId} and chain_status=#{chainStatus} <when test='type==1'> and guardian_check_status=0</when>",
            "</when>",
            " ORDER BY id",
            "</script>"})
    @ResultMap(value = "scoreMap1")
    List<com.cefa.edu.pojo.Score> getScoresWithConditionalByRoleType(Map<String,Object> params);


    /**
     * 查询管理者的学生的状态成绩(一级、二级)
     * @param status
     * @param classIds
     * @param courseIds
     * @param gradeIds
     * @param phaseIds
     * @param chainStatus
     * @return
     */
    @Select({"<script>",
            "SELECT *,2 as role_type FROM cefa_edu_score",
            "WHERE",
            "<when test='status==1'>",
            " (education_stage_id  in(#{phaseIds})  or  grade_id in (${gradeIds}) <when test='classIds!=null'> or level_id in (${classIds})</when> <when test='courseIds!=null'> or course_id in (${courseIds})</when>) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==2'>",
            " ( education_stage_id  in(#{phaseIds})  <when test='classIds!=null'> or level_id in (${classIds})</when> <when test='courseIds!=null'> or course_id in (${courseIds})</when>) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==3'>",
            " (education_stage_id  in(#{phaseIds}) or   grade_id in (${gradeIds}) ) and chain_status=#{chainStatus} <when test='type==1'> and manager_check_status=0</when> ",
            "</when>",
            "<when test='status==4'>",
            "  education_stage_id  in(#{phaseIds}) and chain_status=#{chainStatus} <when test='type==1'> and manager_check_status=0</when>",
            "</when>",
            " ORDER BY id",
            "<when test='pageNo!=null'>",
            " LIMIT #{pageNo}, #{pageCount}",
            "</when>",
            "</script>"})
    @ResultMap(value = "scoreMap1")
    List<com.cefa.edu.pojo.Score> getScoreByids3(@Param("status") Integer status,@Param("classIds") String classIds,@Param("courseIds") String courseIds, @Param("gradeIds") String gradeIds, @Param("phaseIds") String phaseIds, @Param("chainStatus") Integer chainStatus,@Param("pageNo") Integer pageNo,@Param("pageCount") Integer pageCount,@Param("type") Integer type);
    @Select({"<script>",
            "SELECT count(1) FROM cefa_edu_score",
            "WHERE",
            "<when test='status==1'>",
            " (education_stage_id  in(#{phaseIds})  or  grade_id in (${gradeIds}) <when test='classIds!=null'> or level_id in (${classIds})</when> <when test='courseIds!=null'> or course_id in (${courseIds})</when>) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==2'>",
            " ( education_stage_id  in(#{phaseIds})  <when test='classIds!=null'> or level_id in (${classIds})</when> <when test='courseIds!=null'> or course_id in (${courseIds})</when>) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==3'>",
            " (education_stage_id  in(#{phaseIds}) or   grade_id in (${gradeIds}) ) and chain_status=#{chainStatus} <when test='type==1'> and manager_check_status=0</when> ",
            "</when>",
            "<when test='status==4'>",
            "  education_stage_id  in(#{phaseIds}) and chain_status=#{chainStatus} <when test='type==1'> and manager_check_status=0</when>",
            "</when>",
            "</script>"})
    int getScoreByids3Count(@Param("status") Integer status,@Param("classIds") String classIds,@Param("courseIds") String courseIds, @Param("gradeIds") String gradeIds, @Param("phaseIds") String phaseIds, @Param("chainStatus") Integer chainStatus,@Param("type") Integer type);

    /**
     * 只是年级管理者 查询学生状态成绩信息
     * @param status
     * @param classIds
     * @param courseIds
     * @param gradeIds
     * @param chainStatus
     * @return
     */
    @Select({"<script>",
            "SELECT *,3 as role_type FROM cefa_edu_score",
            "WHERE",
            "<when test='status==1'>",
            " ( grade_id in (${gradeIds})  or level_id in (${classIds}) or course_id in (${courseIds}) ) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==3'>",
            " ( grade_id in (${gradeIds})  or  level_id in (${classIds}) ) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==4'>",
            " grade_id in (${gradeIds})  and chain_status=#{chainStatus} <when test='type==1'>and manager_check_status=0</when> ",
            "</when>",
            " ORDER BY id",
            "<when test='pageNo!=null'>",
            " LIMIT #{pageNo}, #{pageCount}",
            "</when>",
            "</script>"})
    @ResultMap(value = "scoreMap")
    List<com.cefa.edu.pojo.Score> getScoreByids4(@Param("status") Integer status,@Param("classIds") String classIds,@Param("courseIds") String courseIds, @Param("gradeIds") String gradeIds, @Param("chainStatus") Integer chainStatus,@Param("pageNo") Integer pageNo,@Param("pageCount") Integer pageCount,@Param("type") Integer type);
    @Select({"<script>",
            "SELECT count(1) FROM cefa_edu_score",
            "WHERE",
            "<when test='status==1'>",
            " ( grade_id in (${gradeIds})  or level_id in (${classIds}) or course_id in (${courseIds}) ) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==3'>",
            " ( grade_id in (${gradeIds})  or  level_id in (${classIds}) ) and chain_status=#{chainStatus}",
            "</when>",
            "<when test='status==4'>",
            " grade_id in (${gradeIds})  and chain_status=#{chainStatus} <when test='type==1'>and manager_check_status=0</when> ",
            "</when>",
            "</script>"})
    int  getScoreByids4Count(@Param("status") Integer status,@Param("classIds") String classIds,@Param("courseIds") String courseIds, @Param("gradeIds") String gradeIds, @Param("chainStatus") Integer chainStatus,@Param("type") Integer type);


    /**
     * 老师班主任角色查询学生的状态成绩
     *@aa add by chaijian 2018-09-06
     * @return
     */
    @Select({"<script>",
            "SELECT a.* ,4 as roleType from",
            " (SELECT * ,4 as role_type FROM cefa_edu_score",
            " WHERE",
            " level_id in (${classIdsForRoleType4}) and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when>",
            "UNION ALL",
            " SELECT * ,5 as roleType FROM cefa_edu_score",
            " WHERE",
            " level_id in (${classIdsForRoleType5}) and course_id in (${courseIdsForRoleType5})  and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when>",
            " )a",
            " ORDER BY a.id",
            "</script>"})
    @ResultMap(value = "scoreMap1")
      // List<com.cefa.edu.pojo.Score> getScoresForTeacherOfRoleType4and5( @Param("classIdsForRoleType4") String classIdsForRoleType4, @Param("classIdsForRoleType5") String classIdsForRoleType5,@Param("courseIdsForRoleType5") String courseIdsForRoleType5, @Param("chainStatus") Integer chainStatus,@Param("pageNo") Integer pageNo,@Param("pageCount") Integer pageCount,@Param("type") Integer type);
    List<com.cefa.edu.pojo.Score> getScoresForTeacherOfRoleType4and5(Map<String,Object> params);

    /**
     * 老师班主任角色查询学生成绩记录数
     *@aa add by chaijian 2018-09-05
     * @return
     */
    @Select({"<script>",
            "SELECT count(1) FROM cefa_edu_score",
            "WHERE",
            "<when test='roleType==4'>",
            " level_id in (${classIdsForRoleType4})  and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when> ",
            "</when>",
            "<when test='roleType==5'>",
            " level_id in (${classIdsForRoleType5}) and course_id in (${courseIdsForRoleType5}) and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when>",
            "</when>",
            "</script>"})
   // int getScoreByidsForRoleType4or5Count(@Param("roleType") Integer roleType, @Param("classIdsForRoleType4") String classIdsForRoleType4, @Param("classIdsForRoleType5") String classIdsForRoleType5,@Param("courseIdsForRoleType5") String courseIdsForRoleType5, @Param("chainStatus") Integer chainStatus,@Param("type") Integer type);
            int getScoreByidsForRoleType4or5Count(Map<String,Object> params);
    /**
     * 老师班主任角色查询学生的状态成绩
     *@aa add by chaijian 2018-09-05
     * @return
     */
    @Select({"<script>",
            "SELECT * ,4 as role_type FROM cefa_edu_score",
            "WHERE",
            "<when test='roleType==4'>",
            " level_id in (${classIdsForRoleType4}) and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when> ",
            "</when>",
            "<when test='roleType==5'>",
            "level_id in (${classIdsForRoleType5}) and course_id in (${courseIdsForRoleType5})  and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when>",
            "</when>",
            " ORDER BY id",
            "<when test='pageNo!=null'>",
            " LIMIT #{pageNo}, #{pageCount}",
            "</when>",
            "</script>"})
    @ResultMap(value = "scoreMap1")
    List<com.cefa.edu.pojo.Score> getScoreByidsForRoleType4or5(Map<String,Object> params);
   // List<com.cefa.edu.pojo.Score> getScoreByidsForRoleType4or5(@Param("roleType") Integer roleType, @Param("classIdsForRoleType4") String classIdsForRoleType4, @Param("classIdsForRoleType5") String classIdsForRoleType5,@Param("courseIdsForRoleType5") String courseIdsForRoleType5, @Param("chainStatus") Integer chainStatus,@Param("pageNo") Integer pageNo,@Param("pageCount") Integer pageCount,@Param("type") Integer type);



    /**
     * 班主任角色查询学生的状态成绩
     *@aa add by chaijian 2018-09-14
     * @return
     */
    @Select({"<script>",
            "SELECT * ,4 as role_type FROM cefa_edu_score",
            "WHERE",
            "<when test='roleType==4'>",
            " level_id in (${classIdsForRoleType4}) and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when> ",
            "</when>",
            " ORDER BY id",
            "</script>"})
    @ResultMap(value = "scoreMap1")
    List<com.cefa.edu.pojo.Score> getScoresForTeacherOfRoleType4(Map<String,Object> params);

    /**
     * 授课老师角色查询学生的状态成绩
     *@aa add by chaijian 2018-09-14
     * @return
     */
    @Select({"<script>",
            "SELECT * ,5 as role_type FROM cefa_edu_score",
            "WHERE",
            "<when test='roleType==5'>",
            "level_id in (${classIdsForRoleType5}) and course_id in (${courseIdsForRoleType5})  and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when>",
            "</when>",
            " ORDER BY id",
            "</script>"})
    @ResultMap(value = "scoreMap1")
    List<com.cefa.edu.pojo.Score> getScoresForTeacherOfRoleType5(Map<String,Object> params);

    /**
     * 老师班主任角色查询学生的状态成绩
     * @param status
     * @param classIds
     * @param courseIds
     * @param chainStatus
     * @return
     */
    @Select({"<script>",
            "SELECT * ,4 as role_type FROM cefa_edu_score",
            "WHERE",
            "<when test='status==1'>",
            " ( level_id in (${classIds}) or course_id in (${courseIds}) ) and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when> ",
            "</when>",
            "<when test='status==2'>",
            " level_id in (${classIds})  and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when>",
            "</when>",
            "<when test='status==3'>",
            " course_id in (${courseIds})  and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when>",
            "</when>",
            " ORDER BY id",
            "<when test='pageNo!=null'>",
            " LIMIT #{pageNo}, #{pageCount}",
            "</when>",
            "</script>"})
    @ResultMap(value = "scoreMap1")
    List<com.cefa.edu.pojo.Score> getScoreByids5(@Param("status") Integer status, @Param("classIds") String classIds, @Param("courseIds") String courseIds, @Param("chainStatus") Integer chainStatus,@Param("pageNo") Integer pageNo,@Param("pageCount") Integer pageCount,@Param("type") Integer type);
    @Select({"<script>",
            "SELECT count(1) FROM cefa_edu_score",
            "WHERE",
            "<when test='status==1'>",
            " ( level_id in (${classIds}) or course_id in (${courseIds}) ) and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when> ",
            "</when>",
            "<when test='status==2'>",
            " level_id in (${classIds})  and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when>",
            "</when>",
            "<when test='status==3'>",
            " course_id in (${courseIds})  and chain_status=#{chainStatus} <when test='type==1'>and instructor_check_status=0</when>",
            "</when>",
            "</script>"})
    int getScoreByids5Count(@Param("status") Integer status, @Param("classIds") String classIds, @Param("courseIds") String courseIds, @Param("chainStatus") Integer chainStatus,@Param("type") Integer type);


//    @Update({"<script>",
//            "update cefa_edu_score set",
//            "<when test='roleType==1||roleType==2||roleType==3'>",
//            " manager_check_name =#{managerCheckName} ,manager_check_status=#{managerCheckStatus} ,manager_check_sign_data=#{managerCheckSignData}",
//            "</when>",
//            "<when test='roleType==4||roleType==5'>",
//            " instructor_check_name =#{instructorCheckName},instructor_check_status=#{instructorCheckStatus} ,instructor_check_sign_data=#{instructorCheckSignData}",
//            "</when>",
//            "<when test='roleType==5||roleType==6'>",
//            " guardian_check_status=#{guardianCheckName},guardian_check_status=#{guardianCheckStatus} ,guardian_check_sign_data=#{guardianCheckSignData}",
//            "</when>",
//            "<when test='type==1'>",
//            " ,chain_status=3",
//            "</when>",
//            "where id=#{id}",
//            "</script>"})
    @Update({ "update cefa_edu_score set  manager_check_name =#{name} ,manager_check_status=#{status} ,manager_check_sign_data=#{data} where id=#{id}" })
    int updateScore1(@Param("name") String name,@Param("status") Integer status,@Param("data") String data,@Param("id") Integer id);
    @Update({ "update cefa_edu_score set  instructor_check_name =#{name},instructor_check_status=#{status} ,instructor_check_sign_data=#{data} where id=#{id}" })
    int updateScore2(@Param("name") String name,@Param("status") Integer status,@Param("data") String data,@Param("id") Integer id);
    @Update({ "update cefa_edu_score set  guardian_check_name=#{name},guardian_check_status=#{status} ,guardian_check_sign_data=#{data} where id=#{id}" })
    int updateScore3(@Param("name") String name,@Param("status") Integer status,@Param("data") String data,@Param("id") Integer id);
    @Update({ "update cefa_edu_score set  chain_status=#{chainStatus} where id=#{id}" })
    int updateScore4(@Param("id") Integer id,@Param("chainStatus") Integer chainStatus);

    /**
     * 已签名学生成绩
     * @param userId
     * @param pageNo
     * @param pageCount
     * @return
     */
    @Select({"SELECT s.* FROM cefa_edu_score s left join cefa_edu_signature_record sr on s.id=sr.data_id left join cefa_edu_user u on u.id=sr.user_id where u.id=#{userId} limit #{pageNo},#{pageCount} "})
    @ResultMap(value = "scoreMap1")
    List<com.cefa.edu.pojo.Score> studentChainData3(@Param("userId")Integer userId,@Param("pageNo") Integer pageNo,@Param("pageCount") Integer pageCount);
    @Select({"SELECT count(1) FROM cefa_edu_score s left join cefa_edu_signature_record sr on s.id=sr.data_id left join cefa_edu_user u on u.id=sr.user_id where u.id=#{userId} "})
    int studentChainData3Count(Integer userId);

    @Update({ "update cefa_edu_score set chain_status = #{chainStatus} where recording_time<#{expiryTime}" })
    int updateScoreChainStatusByDate(@Param("chainStatus") Integer chainStatus,@Param("expiryTime") String expiryTime);

    @Insert({ "insert into cefa_edu_signature_record(user_id,data_id,role_type) values(#{userId},#{dataId},#{roleType})"})
    int insertSignatureRecord(@Param("userId") Integer userId,@Param("dataId") Integer dataId,@Param("roleType")Integer roleType);

    @Update({"update cefa_edu_score set chain_status=1, manager_check_status =0 ,instructor_check_status=0,guardian_check_status=0,manager_check_name=null,instructor_check_name=null,guardian_check_name=null,sign_over_time=1,create_time=#{recordTime},recording_time=#{currentDate} where id=#{scoreId}"})
    int updateScoreCheckStatusByScoreId(@Param("scoreId") Integer scoreId,@Param("currentDate")String currentDate,@Param("recordTime")String recordTime);

    @Select({"select count(sr.id) from cefa_edu_signature_record sr where sr.user_id=#{userId} and sr.data_id=#{scoreId} and sr.role_type=#{roleType}"})
    int getSignatureRecordCount(@Param("userId")Integer userId,@Param("scoreId") Integer scoreId,@Param("roleType") Integer roleType);
}
